#ifndef BOOKMARKSDIALOG_H
#define BOOKMARKSDIALOG_H

#include <QDialog>
#include <QtSql>
#include <QSettings>
#include <QFileInfo>
#include <QDir>
#include <QDateTime>
#include <QMessageBox>
#include <QFileDialog>
#include <QMenu>
#include <QContextMenuEvent>
#include "debugconsole.h"
#include "yasaisqltablemodel.h"

namespace Ui
{
class BookmarksDialog;
}

class BookmarksDialog : public QDialog
{
    Q_OBJECT

public:
    explicit BookmarksDialog(QWidget *parent = 0, DebugConsole *debugconsole = 0, const QString &dbPath = QString());
    ~BookmarksDialog();
    bool saveBookmark(const QFileInfo &fileInfo, const QString &place);
    bool saveLastRead(const QFileInfo &fileInfo, const QString &place);
    bool removeLoadedBookmarksIsChecked();
    void setRemoveLoadedBookmarksChecked(bool checked);
    virtual void contextMenuEvent(QContextMenuEvent *event);
    virtual void showEvent(QShowEvent *);

public slots:
    void on_MenuBookmarksListAboutToShow();
    void on_MenuLastReadListAboutToShow();
    void on_actionBookmarksListTriggered();

private slots:
    void on_bookmarkTableView_activated(const QModelIndex &index);
    void on_lastreadTableView_activated(const QModelIndex &index);
    void on_loadBookmark_clicked();
    void on_removeBookmark_clicked();

    void on_actionVacuum_triggered();
    void on_actionRemoveBookmark_triggered();
    void on_actionRemoveSelectedType_triggered();
    void on_actionRemoveInvalidBookmarks_triggered();    

signals:
    void loadBookmark(const QFileInfo &fileInfo, const QString &place);

private:
    void populateMenu(QMenu* menu, YasaiSqlTableModel* model);

    Ui::BookmarksDialog *ui;
    YasaiSqlTableModel *bookmarksTableModel;
    YasaiSqlTableModel *lastreadTableModel;
    DebugConsole *console;
    QSqlDatabase db;
};

#endif // BOOKMARKSDIALOG_H
